home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 409_01 / test256.c < prev    next >
C/C++ Source or Header  |  1993-10-21  |  9KB  |  278 lines

  1. /****************************************************************************
  2. *
  3. *                          SuperVGA Test Library
  4. *
  5. *                   Copyright (C) 1993 SciTech Software
  6. *                           All rights reserved.
  7. *
  8. * Filename:     $RCSfile: test256.c $
  9. * Version:      $Revision: 1.2 $
  10. *
  11. * Language:     ANSI C
  12. * Environment:  IBM PC (MSDOS)
  13. *
  14. * Description:  Simple program to test the operation of the SuperVGA
  15. *               bank switching code and page flipping code for the
  16. *               256 color SuperVGA video modes.
  17. *
  18. *               MUST be compiled in the large model.
  19. *
  20. * $Id: test256.c 1.2 1993/10/22 08:58:40 kjb release $
  21. *
  22. ****************************************************************************/
  23.  
  24. #include <stdio.h>
  25. #include <stdlib.h>
  26. #include <string.h>
  27. #include <dos.h>
  28. #include <conio.h>
  29. #include "svga.h"
  30.  
  31. /*---------------------------- Global Variables ---------------------------*/
  32.  
  33. #include "version.c"
  34.  
  35. int     x,y;
  36.  
  37. /* External routines */
  38.  
  39. void _copyTest256(void);
  40.  
  41. /*----------------------------- Implementation ----------------------------*/
  42.  
  43. void moireTest(void)
  44. /****************************************************************************
  45. *
  46. * Function:     moireTest
  47. *
  48. * Description:  Draws a simple Moire pattern on the display screen using
  49. *               lines, and waits for a key press.
  50. *
  51. ****************************************************************************/
  52. {
  53.     uchar   buf[80];
  54.     int     i;
  55.  
  56.     clear();
  57.     for (i = 0; i < maxx; i += 10) {
  58.         line(maxx/2,maxy/2,i,0,i % maxcolor);
  59.         line(maxx/2,maxy/2,i,maxy,(i+1) % maxcolor);
  60.         }
  61.     for (i = 0; i < maxy; i += 10) {
  62.         line(maxx/2,maxy/2,0,i,(i+2) % maxcolor);
  63.         line(maxx/2,maxy/2,maxx,i,(i+3) % maxcolor);
  64.         }
  65.     line(0,0,maxx,0,defcolor);
  66.     line(0,0,0,maxy,defcolor);
  67.     line(maxx,0,maxx,maxy,defcolor);
  68.     line(0,maxy,maxx,maxy,defcolor);
  69.  
  70.     if (maxx != 319) {
  71.         x = 80;
  72.         y = 80;
  73.         writeText(x,y,"Bank switching test",defcolor);  y += 32;
  74.         sprintf(buf,"Video mode: %d x %d 256 color",maxx+1,maxy+1);
  75.         writeText(x,y,buf,defcolor);    y += 16;
  76.         sprintf(buf,"Maximum x: %d, Maximum y: %d, BytesPerLine %d, Pages: %d",
  77.             maxx,maxy,bytesperline,maxpage+1);
  78.         writeText(x,y,buf,defcolor);    y += 32;
  79.         writeText(x,y,"You should see a colorful Moire pattern on the screen",defcolor);
  80.         y += 16;
  81.         }
  82.     else {
  83.         x = 40;
  84.         y = 40;
  85.         }
  86.     writeText(x,y,"Press any key to continue",defcolor);
  87.     y += 32;
  88.     getch();
  89. }
  90.  
  91. void readWriteTest(void)
  92. /****************************************************************************
  93. *
  94. * Function:     readWriteTest
  95. *
  96. * Description:  Test the separate read/write bank routines if available.
  97. *               We do this by copying the top 100 scanlines of video memory
  98. *               to another location in video memory.
  99. *
  100. *               This test is desgined to work only in 640 wide video modes.
  101. *
  102. ****************************************************************************/
  103. {
  104.     if (twobanks && (maxx == 639)) {
  105.         _copyTest256();
  106.         writeText(x,y,"To test the separate read/write banks, the top 100 scanlines of",defcolor);
  107.         y += 16;
  108.         writeText(x,y,"this display page should be moved to start at scanline 205.",defcolor);
  109.         y += 16;
  110.         writeText(x,y,"This ensures that a bank boundary will have been crossed",defcolor);
  111.         y += 78;
  112.         writeText(x,y,"Press any key to continue",defcolor);
  113.         getch();
  114.         }
  115. }
  116.  
  117. void pageFlipTest(void)
  118. /****************************************************************************
  119. *
  120. * Function:     pageFlipTest
  121. *
  122. * Description:  Animates a line on the display using page flipping if
  123. *               page flipping is active.
  124. *
  125. ****************************************************************************/
  126. {
  127.     int     i,j,istep,jstep,color,apage,vpage;
  128.     char    buf[80];
  129.  
  130.     if (maxpage != 0) {
  131.         vpage = 0;
  132.         apage = 1;
  133.         setActivePage(apage);
  134.         setVisualPage(vpage);
  135.         i = 0;
  136.         j = maxy;
  137.         istep = 2;
  138.         jstep = -2;
  139.         color = 15;
  140.         while (!kbhit()) {
  141.             setActivePage(apage);
  142.             clear();
  143.             sprintf(buf,"Page %d of %d", vpage+1, maxpage+1);
  144.             if (maxx == 319) {
  145.                 writeText(0,80,"Page flipping - should be no flicker",defcolor);
  146.                 writeText(0,100,buf,defcolor);
  147.                 }
  148.             else {
  149.                 writeText(80,80,"Page flipping - should be no flicker",defcolor);
  150.                 writeText(80,100,buf,defcolor);
  151.                 }
  152.             line(i,0,maxx-i,maxy,color);
  153.             line(0,maxy-j,maxx,j,color);
  154.             vpage = ++vpage % (maxpage+1);
  155.             setVisualPage(vpage);
  156.             apage = ++apage % (maxpage+1);
  157.             i += istep;
  158.             if (i > maxx) {
  159.                 i = maxx-2;
  160.                 istep = -2;
  161.                 }
  162.             if (i < 0)  i = istep = 2;
  163.             j += jstep;
  164.             if (j > maxy) {
  165.                 j = maxy-2;
  166.                 jstep = -2;
  167.                 }
  168.             if (j < 0)  j = jstep = 2;
  169.             }
  170.         getch();                /* Swallow keypress */
  171.         }
  172. }
  173.  
  174. void testingComplete(void)
  175. /****************************************************************************
  176. *
  177. * Function:     testingComplete
  178. *
  179. * Description:  Clears the first display page and puts up a message.
  180. *
  181. ****************************************************************************/
  182. {
  183.     setActivePage(0);
  184.     setVisualPage(0);
  185.     clear();
  186.  
  187.     if (maxx == 319) {
  188.         writeText(0,40,"Testing complete",defcolor);
  189.         writeText(0,60,"press any key to return to text mode",defcolor);
  190.         }
  191.     else
  192.         writeText(80,80,"Testing complete - press any key to return to text mode",defcolor);
  193.     getch();
  194. }
  195.  
  196. int queryCpu(void);
  197.  
  198. void main(void)
  199. {
  200.     int     i,choice,maxmenu;
  201.     int     xres,yres,bitsperpixel,memmodel,maxpage;
  202.     long    pagesize;
  203.     int     menu[20];
  204.     char    buf[80];
  205.  
  206.     if (queryCpu() < 4) {
  207.         printf("This program contains '386 specific instructions, and will not work on\n");
  208.         printf("this machine - sorry\n");
  209.         }
  210.  
  211.     if (initSuperVGA() != 0x102) {
  212.         printf("This program requires a VESA VBE 1.2 compatible SuperVGA. Try installing\n");
  213.         printf("the Universal VESA VBE for your video card, or contact your video card\n");
  214.         printf("vendor and ask for a suitable TSR\n");
  215.         exit(1);
  216.         }
  217.  
  218.     while (true) {
  219. #ifdef  __TURBOC__
  220.         clrscr();
  221. #endif
  222.         printf("256 color SuperVGA test program (Version %s)\n\n",version);
  223.         printf("VBE OEM string: %s\n",OEMString);
  224.         printf("Memory:         %dk\n",memory);
  225.         printf("\n");
  226.         printf("Separate read/write banks: %s\n", twobanks ? "Yes" : "No");
  227.         printf("Extended page flipping:    %s\n", extendedflipping ? "Yes" : "No");
  228.         printf("8 bit wide DAC support:    %s\n", widedac ? "Yes" : "No");
  229.         printf("\n");
  230.         printf("Which video mode to test:\n\n");
  231.  
  232.         maxmenu = 0;
  233.  
  234.         /* Add standard VGA modes to menu */
  235.  
  236.         getSuperVGAModeInfo(menu[maxmenu] = 0x13,&xres,&yres,&bytesperline,
  237.                 &bitsperpixel,&memmodel,&maxpage,&pagesize);
  238.         printf("    [%2d] - %d x %d 256 color (%d page)\n",maxmenu++,
  239.             xres,yres,maxpage+1);
  240.  
  241.         for (i = 0; modeList[i] != -1; i++) {
  242.             /* Filter out the 256 color packed pixel video modes */
  243.  
  244.             if (!getSuperVGAModeInfo(modeList[i],&xres,&yres,&bytesperline,
  245.                     &bitsperpixel,&memmodel,&maxpage,&pagesize))
  246.                 continue;
  247.             if ((bitsperpixel == 8) && (memmodel == memPK)) {
  248.                 printf("    [%2d] - %d x %d 256 color (%d page)\n",maxmenu,
  249.                     xres,yres,maxpage+1);
  250.                 menu[maxme